package serialization;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {

	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
		Student[] s = { new Student("sairam", 23), new Student("karun", 23) };
		Course c = new Course("j2ee", 5000, s);
		c.cid = "a35";
		Course.place = "bangalore";
		// Serialization
		FileOutputStream fout = new FileOutputStream("./test_resources/course.bin");
		ObjectOutputStream obj_out = new ObjectOutputStream(fout);
		obj_out.writeObject(c);
		obj_out.close();
		System.out.println("Object serialized ...");
		Course.place = "hyderabad";
		
		
		// Deserialization
		ObjectInputStream obj_in = new ObjectInputStream(new FileInputStream(
				"./test_resources/course.bin"));
		Course ob = (Course) obj_in.readObject();
		obj_in.close();
		System.out.println("Deserialization completed ...");
		System.out.println("Course name : " + ob.cname);
		System.out.println("Transient members will have default values:"
				+ ob.cid); // transient members are not serialized
		System.out.println("static variable:" + Course.place);// static 
																// variables
																// aren't
																// serialized
        
        Student[] s1=ob.candidates;
        System.out.println(s1[0].name);
        	
	}
}
